<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增资格证书')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-certificate-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">证书名：</label>
                <div class="col-sm-8">
                    <input name="cerName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发布机构：</label>
                <div class="col-sm-8">
                    <input name="cerInstitution" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">证书获取时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="cerGettime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">证书过期时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="cerDeadline" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">指导老师：</label>
                <div class="col-sm-8">
                    <input name="cerInstructor" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">附件路径：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="filePath" class="form-control" type="file">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/certificate"
        $("#form-certificate-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-certificate-add').serialize());
            }
        }

        $("input[name='cerGettime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('cerName', $("input[name='cerName']").val());
            formData.append('cerInstitution', $("input[name='cerInstitution']").val());
            formData.append('cerGettime', $("input[name='cerGettime']").val());
            formData.append('cerInstructor', $("input[name='cerInstructor']").val());
            formData.append('remark', $("input[name='remark']").val());
            formData.append('fileName', $("input[name='fileName']").val());
            formData.append('file', $('#filePath')[0].files[0]);
            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    </script>
</body>
</html>